﻿@inject IStringLocalizer<InputsKeyboard> Localizer

<div>
    <div class="row g-3">
        <div class="col-auto col-form-label">
            <span>@Localizer["InputsKeyboardSpan"]</span>
        </div>
        <div class="col-6">
            <BootstrapInput TValue="string" PlaceHolder="@PlaceHolderText" OnEnterAsync="OnEnterAsync" OnEscAsync="OnEscAsync" />
        </div>
        <div class="col-12">
            <div>@((MarkupString)Localizer["InputsKeyboardTips1"].Value)</div>
        </div>
    </div>
    <p>@((MarkupString)Localizer["InputsKeyboardTips2"].Value)</p>
    <div class="row g-3">
        <div class="col-auto col-form-label">
            <span>@Localizer["InputsKeyboardSpan"]</span>
        </div>
        <div class="col-6">
            <BootstrapInput TValue="string" PlaceHolder="@PlaceHolderText" @ref="Input" OnEnterAsync="OnEnterSelectAllAsync" />
        </div>
    </div>
    <ConsoleLogger @ref="Logger" class="mt-3" />
</div>

@code {
    private string? PlaceHolderText { get; set; }

    [NotNull]
    private Foo? Model { get; set; }

    [NotNull]
    private ConsoleLogger? Logger { get; set; }

    [NotNull]
    private BootstrapInput<string>? Input { get; set; }

    /// <summary>
    /// OnInitialized
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        PlaceHolderText = Localizer["PlaceHolder"];
        Model = new Foo() { Name = Localizer["TestName"] };
    }

    private Task OnEnterAsync(string val)
    {
        Logger.Log($"Enter {Localizer["InputsKeyboardLog"]}: {val}");
        return Task.CompletedTask;
    }

    private Task OnEscAsync(string val)
    {
        Logger.Log($"Esc {Localizer["InputsKeyboardLog"]}: {val}");
        return Task.CompletedTask;
    }

    private async Task OnEnterSelectAllAsync(string val)
    {
        Logger.Log($"Enter call SelectAllText {Localizer["InputsKeyboardLog"]}: {val}");
        await Input.SelectAllTextAsync();
    }
}
